/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
package controller.elementMapper;


public class DatatypePropertyMapper extends PropertyMapper {

	
	//-------------------------------------------------------------------------------------------
	//------------------------ insert, select, update -----------------------------------
	//	-----------------------------------------------------------------------------------------
	

	/*
	public static URI copy( URI oldId, String newLabel ) throws Exception {
		
		URI ret = null;
		
		DatatypePropertyContainer cont = select( oldId, Vocabulary.ENGLISH );		
		cont.setLabel( newLabel );		
		URI newId = insert( cont, Vocabulary.ENGLISH );	
		
		if( newId!=null ) {
			
			// mark the old ID, that it was renamed:				
			AbstractDataConnector.insertTripel( oldId, Vocabulary.WASRENAMEDTO, newId );
			
			ret = newId;
		}
		
		return ret;		
	}
	*/

	/**
	 * insert an DatatypeProperty into the sesame store
	 * @param data an DatatypeProperty object
	 * @param lang the language in which the DatatypeProperty should be inserted
	 * @return true if the DatatypeProperty was inserted
	 *//*
	public static URI insert(DatatypePropertyContainer data, String lang) throws ControllerException{
		URI ret = null;
	
		try {

			RepositoryConnection con = AbstractDataConnector.getConnection();	

			//insert the class specific data (domain, range)
			try {
				
				URI id = PropertyMapper.insert(con, data, lang);
				
				//insert all the data of the AbstractElement
				if ( id != null ) {

					con.add(id, Vocabulary.RANGE, data.getRange());
					
					
					con.commit();
					
					ret = id;
				}
				else {
					con.rollback();
				}
			} catch( Exception e ) {
				con.rollback();	
				throw e;
			} finally {
				con.close();
			}			
		} catch (Exception e) {
			System.out.println("inserting the DTP failed: " + e.getMessage());
			if (e instanceof ControllerException)
				throw (ControllerException) e;
		}
		
		return ret;
	}
	*/
	

	/*
	public static DatatypePropertyContainer select(URI uri, String lang) {

		DatatypePropertyContainer ret = new DatatypePropertyContainer();
		
		try {

			ret.setLabel( selectLabel(uri, lang) );
			ret.setComment( selectComment(uri, lang) );
			
			ret.setHasVersionDateTime( selectHasVersionDateTime( uri ) );
			ret.setHasPreviousVersion( AbstractDataConnector.selectObject(uri, Vocabulary.HASPREVIOUSVERSION ) );
			
			ret.setSeeAlso( selectSeeAlso(uri) );
			
			ret.setTranslations( selectTranslation( uri ) );
			
			ret.setSynonyms( selectSynonyms(uri) );
			ret.setTags( selectTags(uri) );
			ret.setFlickrImages( selectImages(uri) );
			ret.setYouTubeVideos( selectVideos(uri) );

			ret.setExample( selectExample(uri) );	

			ret.setDomain( selectDomain(uri));
			ret.setRange( selectRange(uri).get(0) );
			ret.setBelongsToOntologyModule( selectBelongsToOM(uri));
			
			ret.setId(uri);
			
		} catch (Exception e) {
			System.out.println("Error while selecting uri " + uri + ": " + e.getMessage());
		}
		
		return ret;
	}
	*/
	


	/*
	public static boolean update(URI uri, DatatypePropertyContainer new_cont, String lang ) {
		boolean ret = false;

		try {
			RepositoryConnection con = AbstractDataConnector.getConnection();
			try {				

				updateComment(con, uri, new_cont.getComment(), lang );
				updateExample(con, uri, new_cont.getExample() );
				updateSynonyms(con, uri, new_cont.getSynonyms() );
				updateTags( con, uri, new_cont.getTags() );
				updateImages( con, uri, new_cont.getFlickrImages() );
				updateVideos( con, uri, new_cont.getYouTubeVideos() );
				
				updateTranslations( con, uri, new_cont.getTranslations() );
				
				updateSeeAlso( con, uri, new_cont.getSeeAlso() );
				
				updateBelongsToOM( con, uri, new_cont.getBelongsToOntologyModule() );
				
				updateDomain( con, uri, new_cont.getDomain() );
				
				updateRange( con, uri, new_cont.getRange() );
				
				con.commit();
				ret = true;
			} catch( Exception e ) {
				con.rollback();		
				throw e;			
			} finally {
				con.close();
			}
		}catch (Exception e) {
			System.out.println("error during update of class: " + e.getMessage());
		}
		
		return ret;
	}
	*/
	
	/*
	public static ArrayList<URI> selectAll() {
		
		return AbstractDataConnector.selectAllUris( Vocabulary.DATATYPEPROPERTY );	
	}
	*/


	// ######################################################################################
	// ######################################################################################

	/*
	public static URI selectRange( URI uri ) throws Exception {
		URI ret = null;
		
		ArrayList<URI> tmp = generateURIObjects(uri, Vocabulary.RANGE );
		
		if( tmp!=null && tmp.size()!=0 )
			ret = (URI)tmp.get(0);
			
		return ret;
	}	
	public boolean updateRange( RepositoryConnection con, URI uri, String entry, String oldentry ) throws Exception {

		boolean ret = false;
		
		entry = trimEntry(entry);		
		oldentry = trimEntry(oldentry);
		
		try {
	
			URI actualEntry = selectRange(uri);
			URI newEntry = new URIImpl( entry );
	
			Mapper.checkIfStoredInMeantime(
				actualEntry.toString(),
				oldentry );
			
			ArrayList<URI> newlist = null;
			if( entry!=null ) {
				newlist = new ArrayList<URI>();
				newlist.add( newEntry );
			}
	
			ArrayList<URI> oldlist = null;
			if( entry!=null ) {
				oldlist = new ArrayList<URI>();
				oldlist.add( actualEntry );
			}
			
			VersioningMapper.archiveRemoveInsertURIs(
					con, 
					oldlist, 
					newlist, 
					uri, 
					Vocabulary.RANGE );
			ret = true;
		}
		catch( Exception ex ) {
			this.addExceptionRange( ex );
		}
		
		return ret;	
	}
	public boolean insertRange( RepositoryConnection con, URI uri, URI entry ) throws Exception {

		boolean ret = false;
		
		try {

			con.add(uri, Vocabulary.RANGE, entry);
			
			ret = true;
		}
		catch( Exception ex ) {
			this.addExceptionRange( ex );
		}
		
		return ret;
	}
	*/

}
